package com.example.kspo_enjoysports;

import java.util.ArrayList;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Context;
import android.database.Cursor;
import android.os.AsyncTask;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;

import com.example.kspo_enjoysports.vo.RegistVO;

public class RegistResultActivity extends Activity {

	ArrayList<RegistVO> data_arr;
	ListView regist_result_list;
	Context context;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.regist_result_layout);
		context = RegistResultActivity.this;
		data_arr = new ArrayList<RegistVO>();
		findView_setting();
//		new GetDB_Data_AsyncTask().execute();
		getDataSetting();
//		RegistResultAdapter adapter = new RegistResultAdapter(context, R.layout.retist_result_list_textitem, data_arr);
//		regist_result_list.setAdapter(adapter);
	}
	
	private void findView_setting()
	{
		regist_result_list = (ListView)findViewById(R.id.regist_result_list);
		
	}
	
	RegistVO rvo;
	Cursor cursor;
	public void getDataSetting(){
		
		cursor = Global.DB_handler.selectAll();
//		int count = cursor.getCount();
		
		while(cursor.moveToNext())
		{
			rvo = new RegistVO();
			rvo.setClub_name(cursor.getString(0));
			rvo.setRegister(cursor.getString(1));
			rvo.setPhone_num(cursor.getString(2));
			rvo.setSport_type(cursor.getString(3));
			rvo.setBig_locate(cursor.getString(4));
			rvo.setSecond_loacte(cursor.getString(5));
			rvo.setLongitude(cursor.getString(6));
			rvo.setLatitude(cursor.getString(7));
			rvo.setMember_count(cursor.getString(8));
			rvo.setClub_introduce(cursor.getString(9));
//			rvo.setClub_pw(cursor.getString(10));
			
			data_arr.add(rvo);
		}
		cursor.close();
		
		
		RegistResultAdapter adapter = new RegistResultAdapter(context, R.layout.retist_result_list_textitem, data_arr);
		regist_result_list.setAdapter(adapter);
		
	}
	
	
	
	
//	
//	class GetDB_Data_AsyncTask extends AsyncTask<Void, Void, Void>{
//
//		@Override
//		protected Void doInBackground(Void... params) {
//			// TODO Auto-generated method stub
//			
//			
//			
//			
//			return null;
//		}
//
//		@Override
//		protected void onPostExecute(Void result) {
//			// TODO Auto-generated method stub
//			super.onPostExecute(result);
//			
//			RegistResultAdapter adapter = new RegistResultAdapter(context, R.layout.retist_result_list_textitem, data_arr);
//			regist_result_list.setAdapter(adapter);
////			this.cancel(true);
//		}
//		
//		
//	}
	
	class RegistResultAdapter extends ArrayAdapter<RegistVO>{

		ArrayList<RegistVO> items_arr = new ArrayList<RegistVO>();;
		Context context;
		
		TextView text01;
		TextView text02;
		TextView text03;
		TextView text04;
		TextView text05;
		TextView text06;
		TextView text07;
		TextView text08;
		
		public RegistResultAdapter(Context context, int resource, ArrayList<RegistVO> items) {
			super(context, resource,  items);
			// TODO Auto-generated constructor stub
			this.context = context;
			this.items_arr = items;
			
		}

		@Override
		public int getCount() {
			// TODO Auto-generated method stub
			return items_arr.size();
		}

		public View getView(int position, View convertView, ViewGroup parent) {
			// TODO Auto-generated method stub
			
			View v = convertView;
			if(v == null){
				LayoutInflater inflater = LayoutInflater.from(context);
				v = inflater.inflate(R.layout.retist_result_list_textitem, null);
			}
			
			RegistVO rvo = new RegistVO(); 
			rvo = items_arr.get(position);
			
			text01 = (TextView)v.findViewById(R.id.re_text01);
			text02 = (TextView)v.findViewById(R.id.re_text02);
			text03 = (TextView)v.findViewById(R.id.re_text03);
			text04 = (TextView)v.findViewById(R.id.re_text04);
			text05 = (TextView)v.findViewById(R.id.re_text05);
			text06 = (TextView)v.findViewById(R.id.re_text06);
			text07 = (TextView)v.findViewById(R.id.re_text07);
			text08 = (TextView)v.findViewById(R.id.re_text08);
			
			
			if(rvo.getClub_name() ==null ){
				text01.setText("");
			}else {
				text01.setText(rvo.getClub_name());
			}
			if(rvo.getClub_name() ==null ){
				text02.setText("");
			}else {
				text02.setText(rvo.getRegister());
			}
			if(rvo.getClub_name() ==null ){
				text03.setText("");
			}else {
				text03.setText(rvo.getPhone_num());
			}
			if(rvo.getClub_name() ==null ){
				text04.setText("");
			}else {
				text04.setText(rvo.getSport_type());
			}
			if(rvo.getClub_name() ==null ){
				text05.setText("");
			}else {
				text05.setText(rvo.getBig_locate());
			}
			if(rvo.getClub_name() ==null ){
				text06.setText("");
			}else {
				text06.setText(rvo.getSecond_loacte());
			}
			if(rvo.getClub_name() ==null ){
				text07.setText("");
			}else {
				text07.setText(rvo.getLongitude());
			}
			if(rvo.getClub_name() ==null ){
				text08.setText("");
			}else {
				text08.setText(rvo.getLatitude());
			}
			
			
			return v;
		}
		
		
		
	}
	

	
	
}
